{extend name="layout" /}
{block name="body"}
<div class="row">
    <div class="col-lg-12">
        <div class="card">
            <ul class="nav nav-tabs page-tabs pt-2 pl-3 pr-3">
                <li class="nav-item"> <a href="{:url('system/email')}" class="nav-link active">邮箱配置</a> </li>
                <li class="nav-item"> <a href="{:url('system/phone')}" class="nav-link">验证码配置</a> </li>
            </ul>
            <div class="tab-content">
                <div class="tab-pane active">
                    <div class="edit-form">
                        <div class="form-group">
                            <label for="username">邮箱账号</label>
                            <input type="hidden" class="form-control" id="typename" value="email">
                            <input type="text" class="form-control" id="username" value="{$email.username}" placeholder="请输入邮箱账号">
                        </div>
                        <div class="form-group">
                            <label for="password">账号密码(授权码)</label>
                            <input type="text" class="form-control" id="password" value="{$email.password}" placeholder="请输入账号密码(授权码)">
                        </div>
                        <div class="form-group">
                            <label for="host">发信方式</label>
                            <input type="text" class="form-control" id="host" value="{$email.host}" placeholder="请输入发信方式">
                        </div>
                        <div class="form-group">
                            <label for="port">发信端口</label>
                            <input type="text" class="form-control" id="port" value="{$email.port}" placeholder="请输入发信端口">
                        </div>
                        <div class="form-group">
                            <label for="subject">发信标题</label>
                            <input type="text" class="form-control" id="subject" value="{$email.subject}" placeholder="请输入发信标题">
                        </div>
                        <div class="form-group">
                            <label for="test_email">测试邮箱</label>
                            <input type="email" class="form-control" id="test_email" placeholder="请输入测试邮箱">
                        </div>
                        <button type="button" onclick="updateemail()" class="btn btn-w-sm btn-primary mb-2">保存</button>
                        <button type="button" class="btn btn-w-sm btn-info mb-2" onclick="testemail()">测 试</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="js"}
<script>
    function updateemail() {
        var l = $('body').lyearloading({
            opacity: 0.2,
            spinnerSize: 'lg',
            spinnerText: '后台处理中，请稍后...',
            textColorClass: 'text-info',
            spinnerColorClass: 'text-info'
        });
        var typename = $.trim($("#typename").val());
        var username = $.trim($("#username").val());
        var password = $.trim($("#password").val());
        var host = $.trim($("#host").val());
        var port = $.trim($("#port").val());
        var subject = $.trim($("#subject").val());
        $.ajax({
            type: "POST",
            url: "{:url('system/email')}",
            data: {
                typename: typename,
                username: username,
                password: password,
                host: host,
                port: port,
                subject: subject,
            },
            dataType: "json",
            success: function (data) {
                setTimeout(function () {
                    l.destroy();
                }, 1e3)
                if (data.code == 1) {
                    notify.success(data.msg);
                } else {
                    notify.error(data.msg);
                }
            },
            error: function () {
                l.destroy();
                notify.error("系统错误");
            }
        })
    }

    function testemail() {
        var l = $('body').lyearloading({
            opacity: 0.2,
            spinnerSize: 'lg',
            spinnerText: '后台处理中，请稍后...',
            textColorClass: 'text-info',
            spinnerColorClass: 'text-info'
        });
        var test_email = $.trim($("#test_email").val());
        if (test_email == "" || test_email == null) {
            l.destroy();
            notify.error("请输入测试邮箱账号");
            return false;
        }
        $.ajax({
            type: "POST",
            url: "{:url('system/TestEmail')}",
            data: {
                test_email: test_email
            },
            dataType: "json",
            success: function (data) {
                setTimeout(function () {
                    l.destroy();
                }, 1e3)
                if (data.code == 200) {
                    notify.success(data.msg);
                } else {
                    notify.error(data.msg);
                }
            },
            error: function () {
                l.destroy();
                notify.error("系统错误");
            }
        })
    }
</script>
{/block}